/**********************************************************************************************/
/* FBL_Value_Date.h 	                                                   					  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006															  */
/* All Rights Reserved                                                   					  */
/**********************************************************************************************/

#ifndef _FBL_Value_Date_h
	#define _FBL_Value_Date_h
#pragma once

#include <VShared/FBL/publ/Interfaces/FBL_I_ValueDate.h>

// FBL:
#include <VShared/FBL/publ/Values/FBL_Value_Numeric.h>

#include <VShared/FBL/publ/Headers/FBL_pre_header.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
SMART_CLASS(Value_date);
SMART_CLASS(Value_date_null);


/**********************************************************************************************/
union DateEncoded;
enum EDateFormat;


/**********************************************************************************************/
// FAST STR => DATE
// Returns the number of digits in year representation.
//
FBL_SHARED_EXP ushort Convert_str_date_aa_fast( 	// char* => DATE
	const char*			inStr, 
	const DTFormat*		inFormat,
	DateEncoded&		outDateEnc );
	
FBL_SHARED_EXP ushort Convert_str_date_uu_fast( 	// UChar* => DATE
	const UChar*		inStr, 
	const UChar*		inStrEnd, 
	const DTFormat*		inFormat,
	DateEncoded&		outDateEnc );
	

/**********************************************************************************************/
// FAST DATE => STR
//
FBL_SHARED_EXP tslen Convert_date_str_fast( 		// DATE => char*
	const DateEncoded&	inDateEnc, 
	const EDateFormat	inDateFormat,
	const char			inSep, 
	char*				outString );

// DATE => UChar*
FBL_SHARED_EXP tslen Convert_date_str_fast( 		// DATE => UChar*
	const DateEncoded&	inDateEnc, 
	const EDateFormat	inDateFormat,
	const UChar			inSep, 
	UChar*				outString );


/**********************************************************************************************/
// CONVERT with CHECKS
//
FBL_SHARED_EXP void Convert_str_date_aa_aux( 					// char* => DATE
	const char*			inStr,
	const DTFormat* 	inDTFormat,
	DateEncoded&		ioDate );

FBL_SHARED_EXP void Convert_str_date_uu_aux( 					// UChar* => DATE
	const UChar*		inStr,
	const UChar*		inStrEnd,
	const DTFormat* 	inDTFormat,
	DateEncoded&		ioDate );


/**********************************************************************************************/
// VALUE STRING <=> VALUE DATE
//
FBL_SHARED_EXP void Convert_str_date( 					
	const I_Value*	inValue, 
	I_Value*		outValue );

FBL_SHARED_EXP void Convert_date_str( 
	const I_Value*	inValue, 
	I_Value*		outValue );


#pragma mark === Value_date_imp ===


/**********************************************************************************************/
// This class implements I_ValueDate interface
// 
class FBL_SHARED_EXP_CLASS Value_date_imp : 
	public I_ValueDate, 
	public Value_Numeric< kTypeDate, vcDate, policyInPlace_long >
{
		IMPLEMENT_UNKNOWN(Value_date_imp)											
		BEGIN_INTERFACE_TABLE(Value_date_imp)										
			IMPLEMENT_INTERFACE(I_Value)										
			IMPLEMENT_INTERFACE(I_Serializable)										
			IMPLEMENT_INTERFACE(I_ValueDate)										
		END_INTERFACE_TABLE()

	public://///////////////////////////////////////////////////////////////////////////////////

							Value_date_imp( const DTFormat* inDTFormat = NULL );

							Value_date_imp( 
								const Value_date_imp&	inOther,
								const DTFormat*			inDTFormat = NULL );


virtual						~Value_date_imp( void );


	// ---------------------
	// DateTimeFormat:
	
		// <DateTimeFormat> [r/w]
virtual	void				put_DTFormat( const DTFormat* inDTFormat ) throw();
virtual	const DTFormat*		get_DTFormat( void ) const throw();

	// ---------------------
	// Date properties:
	
virtual	long				get_Year( void ) const;
virtual	void				put_Year( long inYear );

virtual	ushort				get_Month( void ) const;
virtual	void				put_Month( ushort inMonth );

virtual	ushort				get_Day( void ) const;
virtual	void				put_Day( ushort inDay );

virtual	void				get_Date( 
								long&	outYear, 
								ushort& outMonth, 
								ushort& outDay ) const;

virtual	void				put_Date( 
								long	inYear, 
								ushort	inMonth, 
								ushort	inDay );



	public://///////////////////////////////////////////////////////////////////////////////////

// I_Value API:

		using Value_Numeric< kTypeDate, vcDate, policyInPlace_long >::Assign;

	// ---------------------
	// Properties:

virtual ulong				get_MaxChars( void ) const throw();


	// ---------------------
	// get/put string:

virtual String				get_String( tslen inLimit = -1 ) const;
virtual void				put_String( const String& inStr );

virtual UChar*				get_String( 
								UChar* 			outString, 
								tslen 			inBufferChars = -1 ) const;

virtual void				put_String( 
								const UChar* 	inStart,
								const UChar* 	inEnd = NULL );
								
virtual char*				get_String( 
								char* 			outString, 
								tslen 			inBufferChars = -1 ) const;

virtual void				put_String( 
								const char* 	inStart,
								const char* 	inEnd = NULL );


	// ---------------------
	// Numeric properties:

virtual void				put_Boolean( bool inValue )			{ argused1( inValue ); }
virtual bool				get_Boolean( void ) const			{ return ( bool )( 0 ); }

virtual void				put_Byte( uchar inValue )			{ argused1( inValue ); }
virtual uchar				get_Byte( void ) const				{ return ( uchar )( 0 ); }

virtual void				put_Short( short inValue )			{ argused1( inValue ); }
virtual short				get_Short( void ) const				{ return ( short )( 0 ); }

virtual void				put_UShort( ushort inValue )		{ argused1( inValue ); }
virtual ushort				get_UShort( void ) const			{ return ( ushort )( 0 ); }

virtual void				put_Medium( long inValue )			{ argused1( inValue ); }
virtual long				get_Medium( void ) const			{ return ( long )( 0 ); }

virtual void				put_LLong( llong inValue )			{ argused1( inValue ); }
virtual llong				get_LLong( void ) const				{ return ( llong )( mValue ); }

virtual void				put_ULLong( ullong inValue )		{ argused1( inValue ); }
virtual ullong				get_ULLong( void ) const			{ return ( ullong )( 0 ); }

virtual void				put_Float( float inValue )			{ argused1( inValue ); }
virtual float				get_Float( void ) const				{ return ( float )( 0 ); }

virtual void				put_Double( double inValue )		{ argused1( inValue ); }
virtual double				get_Double( void ) const			{ return ( double )( 0 ); }


	public://///////////////////////////////////////////////////////////////////////////////////

//#if FBL_TEST_CODE

virtual void				Init( void ) throw();
virtual void 				Increment( void ) throw(); 

//#endif // FBL_TEST_CODE


	protected://////////////////////////////////////////////////////////////////////////////////

		const DTFormat*		mDTFormat;			///< Date and time format.
		bool				mDTFormatOwner;
};


#pragma mark === Value_date ===


/**********************************************************************************************/
// Implements Value date.
// 
class FBL_SHARED_EXP_CLASS Value_date : public Value_date_imp
{

public://///////////////////////////////////////////////////////////////////////////////////

							Value_date( 
								const DTFormat* inDTFormat = NULL );
							
							Value_date( 
								const Value_date&	inOther,
								const DTFormat*		inDTFormat = NULL );

							Value_date( 
								long	inYear,
								ushort	inMonth,
								ushort	inDay,
								const DTFormat*	inDTFormat = NULL );


virtual						~Value_date( void );


virtual	I_Value_Ptr			Clone( bool inCopyData = true ) const throw();

};


#pragma mark === Value_date_null ===


/**********************************************************************************************/
// Implements nullable Value date.
// 
class FBL_SHARED_EXP_CLASS Value_date_null : 
	public Value_date,
	protected policyNullable< policyInPlace_long >
{						

	public:///////////////////////////////////////////////////////////////////////////////////

		typedef policyNullable<policyInPlace_long>					PN;


public:///////////////////////////////////////////////////////////////////////////////////

							Value_date_null( 
								const DTFormat* 	inDTFormat = NULL );
							
							Value_date_null( 
								const Value_date&	inOther,
								const DTFormat*		inDTFormat = NULL );

							Value_date_null( 
								long	inYear,
								ushort	inMonth,
								ushort	inDay,
								const DTFormat*	inDTFormat = NULL );


virtual						~Value_date_null( void );


virtual	I_Value_Ptr			Clone( bool inCopyData = true ) const throw();

virtual bool				get_IsNullable( void ) const throw() { return true; }
virtual bool 				get_IsNull( void ) const throw();
virtual void 				put_IsNull( bool inValue ) throw();
							
							
	// ---------------------
	// Value compare methods:

virtual	int					Compare( 
								const I_Value& 	inOther, 
								COMPARE_TYPE 	inCompareType = kNatureCompare ) const throw();							

virtual String				get_String( 
								tslen 		inLimit = -1 ) const;

virtual UChar*				get_String( 
								UChar* 		outString, 
								tslen 		inBufferChars = -1 ) const;

virtual char*				get_String( 
								char* 		outString, 
								tslen 		inBufferChars = -1 ) const;

};


/**********************************************************************************************/
FBL_End_Namespace

#include <VShared/FBL/publ/Headers/FBL_post_header.h>

#endif // _FBL_Value_Date_h
